#pragma once
#include <DataStorageBase.h>
#include <mail.h>
#include <module_header_reg.h>
#include <module_general_reg.h>

#define DATA_STORAGE_MODULE_GENERAL_BEGIN_ADDRESS 40

#define DATA_STORAGE_MOTOT1_ADDRESS (int)(DATA_STORAGE_MODULE_GENERAL_BEGIN_ADDRESS)
#define DATA_STORAGE_MOTOT2_ADDRESS (int)(DATA_STORAGE_MOTOT1_ADDRESS   +   DATA_STORAGE_MODULE_GENERAL_INFO_SIZE)
#define DATA_STORAGE_MOTOT3_ADDRESS (int)(DATA_STORAGE_MOTOT2_ADDRESS   +   DATA_STORAGE_MODULE_GENERAL_INFO_SIZE)

#define DATA_STORAGE_EOF_ADDRESS   (int)(sizeof(module_general_reg_t)+DATA_STORAGE_MODULE_GENERAL_BEGIN_ADDRESS)


class DataStorageStepper: public DataStorageBase
{
public:

    typedef struct
    {
        module_header_reg_t       module_header_reg;     //39字节
        module_general_reg_t     module_general_reg;        //108字节
    }module_stepper_motor_reg_t;

    DataStorageStepper(Mail<>& mb);
    void begin() override;
    void make_default() override;

    bool load() override;

    int read_data_storage_eof() override;
    
    void check_update() override;

    module_header_reg_t& module_header_reg() override
    {
        return DataStorageStepper::module_reg().module_header_reg;
    }

    data_storage_reg_read_t& get_reg_data(uint8_t reg_address) override;
    
    
    static module_stepper_motor_reg_t& module_reg()
    {
        static module_stepper_motor_reg_t module_reg;
        return module_reg;
    }
protected:
    constexpr uint32_t data_storage_header_size()
    {
        return sizeof(DataStorageStepper::module_reg().module_header_reg.data);
    }
    constexpr uint32_t data_storage_general_size()
    {
        return sizeof(DataStorageStepper::module_reg().module_general_reg.data);
    }

private:
    //数据存储的头部
    data_storage_eof_t _data_storage_eof;
    data_storage_reg_read_t _reg_read;
    Mail<>& _mb;


};

